package com.cat.dataStructure03;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-all-lonely-numbers-in-the-array/
 * @create 2025/11/3 16:50
 * @since JDK17
 */

public class Solution07 {
    public List<Integer> findLonely(int[] nums) {
        int max = 0;
        int[] cnt = new int[((int) 1e6) + 5];
        for (int x : nums) {
            cnt[x]++;
            max = Math.max(max, x);
        }
        List<Integer> ans = new ArrayList<>();
        if (cnt[0] == 1 && cnt[1] == 0) {
            ans.add(0);
        }
        for (int i = 1; i <= max; i++) {
            if (cnt[i] == 1 && cnt[i - 1] == 0 && cnt[i + 1] == 0) {
                ans.add(i);
            }
        }
        return ans;
    }
}
